<%@ page language="java" %>
<%@ page session="true" %>
<%@ page import="java.sql.*,java.io.*,java.util.Random,java.util.Enumeration"%>

<%	
String userr="";
userr = (session.getAttribute("userr")==null) ? "Null" : (String)session.getAttribute("userr"); 

if(userr.equals("Null"))
{
	session.invalidate();
	%>
	<!--<H5 align=center><IMG SRC="Images/error.gif" WIDTH="17" HEIGHT="13" BORDER=0 ALT="">Session time out...Please login again</H5>-->
	<script language=javascript>
		location.replace('sessiontimeout.html');
	</script>
	<% 
}
else{
%>
<head>
<title>Downloads</title>
<link rel="STYLESHEET" type="text/css" href="styles.css">
<SCRIPT LANGUAGE="JavaScript">
<!--
//-->
</SCRIPT>
</head>
<BODY  Class="Grad">
<FORM METHOD=POST ACTION="" NAME="DownloadsForm">
<input type="hidden" name="Result" value="">
<H3 align=center><FONT SIZE="" COLOR="#000000">Downloads</FONT></h3>
<center>
<%
	String fullpath = application.getRealPath(request.getServletPath());
	String dirpath = fullpath.substring(0,fullpath.lastIndexOf("\\"));
	String DownloadsPath = dirpath+"/Downloads/";
	String Category = request.getParameter("Category");
	//System.out.println("-----------Category--------"+Category);
	DownloadsPath+=Category;
                                                                                    
	File dir = new File(DownloadsPath);
	//System.out.println("-----------dir--------"+dir);

    // The list of files can also be retrieved as File objects
    File[] files = dir.listFiles();
    // This filter only returns doc,zip files
    FileFilter fileFilter1 = new FileFilter() {
        public boolean accept(File file) {
             return (!file.isDirectory() && (file.getName().endsWith(".zip")||file.getName().endsWith(".ZIP")));
        }
    };
	//System.out.println(dirpath+"-----------fileFilter1--------"+fullpath); 
	%>
	<table width="30%" align="center">
	<tr class=row_title>
		<th >Download Name</th>
	</tr>
	<%
	File[] dFiles = dir.listFiles(fileFilter1);
	String[] FileNames = dir.list();
	//System.out.println("-----------dFiles--------"+FileNames);

	String FileName;
	for(int i=0;i<dFiles.length;i++)
	{       
		 FileName=dFiles[i].getName();
		 %>
		 <tr class=<%= ((i%2==0) ? "row_even" : "row_odd") %> >
			 <td align="center">
				<A HREF="FileDownloads.jsp?fileName=<%=dFiles[i].getPath()%>"><%=dFiles[i].getName().toUpperCase()%></A>
				<Input type = "Hidden" name="Files" value="<%=dFiles[i].getName()%>">
			 </td>
        </tr>
		<%
	}

		if(files.length==0){
			%><TR><TD colspan=4><H3 align=center> <FONT COLOR="#FF6633">Downloads are currently not available, please visit again</FONT></H3></td></TR><%
		}
%>
</table>
</FORM>
<%
